<?php
// +----------------------------------------------------------------------
// | 美胸汇 [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.dongdang.xin All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: tiedong <2547337875@qq.com>
// +----------------------------------------------------------------------
namespace app\api\model;

class PortalPostModel extends BaseModel
{
    protected $hidden = [
        'parent_id', 'post_type', 'post_format', 'user_id', 'post_status',
        'comment_status', 'is_top', 'recommended', 'post_hits', 'post_favorites', 'post_like',
        'comment_count', 'create_time','update_time','published_time','delete_time','more'];

    /**
     * post_content 自动转化
     * @param $value
     * @return string
     */
    public function getPostContentAttr($value)
    {
        return cmf_replace_content_file_url(htmlspecialchars_decode($value));
    }

    /**
     * post_content 自动转化
     * @param $value
     * @return string
     */
    public function setPostContentAttr($value)
    {
        return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
    }

    /**
     * published_time 自动完成
     * @param $value
     * @return false|int
     */
    public function setPublishedTimeAttr($value)
    {
        return strtotime($value);
    }

    public function getThumbnailAttr( $value,$data )
    {
        return $this->prefiwThumbnailUrl( $value,$data );
    }

    //获取文章条数
    public static function getMostArticle( $count )
    {
        $articles = self::limit($count)
            ->where('post_status','=','1')
            ->select();
        return $articles;
    }

    //获取文章详情
    public static function getArticleDetail( $id )
    {
        $detail = self::where('id','=',$id)
            ->find();
        return $detail;
    }


}
